<?php

class Ev_View_Helper_TreeViewOrganograma extends Zend_View_Helper_FormSelect
{
    public function treeViewOrganograma($rowSet, $moduleControllerAction, $stCampoChave, $stCampoCodigo, $stCampoDescricao, $aUsuarios = null)
    {
        $html = '';
        foreach ($rowSet as $indiceFilho => $row) {
            $stNome = $stEmail = '';
            if (isset($aUsuarios[$row->fk_usuario_responsavel])) {
                $rowUsuario = $aUsuarios[$row->fk_usuario_responsavel];
                $stNome  = $rowUsuario->st_nome;
                $stEmail = $rowUsuario->st_email;
            }
            $html .=
            '
            <li>' . $this->view->gravatar($stEmail, array('img_size' => 32),
                                                          array('alt' => $stNome,
                                                                'title' => $stNome,
                                                                'style' => 'margin:0px 10px 10px 0px;')) . ' <br />

                <a href="' . $moduleControllerAction . '/' . $stCampoChave . '/' . $row->$stCampoChave . '">' . $row->$stCampoCodigo . ' - ' . $row->$stCampoDescricao . '</a>
            ';
            if ($row->filhos) {
                    $html .= '
                <ul>
                    ' . $this->treeViewOrganograma($row->filhos, $moduleControllerAction, $stCampoChave, $stCampoCodigo, $stCampoDescricao, $aUsuarios) . '
                </ul>';
            }
            $html .= '</li>';
        }
        return $html;
    }
}
